import { ApiProperty } from '@nestjs/swagger';
import { modelOptions, prop, Ref } from '@typegoose/typegoose';
import { Car } from './car.model';
import { User } from './user.model';

@modelOptions({
  schemaOptions: {
    toJSON: {
      virtuals: true,
    },
    toObject: {
      virtuals: true,
    },
    timestamps: true,
  },
})
export class Order {
  @ApiProperty({ description: '订单状态', example: 0 })
  @prop({ required: true, default: 0 })
  status: number;

  @ApiProperty({ description: '用户ID', example: 'xxxxx' })
  @prop({ required: true, ref: 'User' })
  user: Ref<User>;

  @ApiProperty({ description: '快递单号', example: 'xxxxx' })
  @prop()
  express: string;

  @prop({
    ref: () => Car,
    localField: '_id',
    foreignField: 'order',
  })
  cars: Ref<Car>[];
}
